package com.appview;


import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;

import javax.swing.*;

import com.appdatebase.CheckUserInfo;
import com.appdatebase.QueryUserInfo;

public class MainView extends JFrame implements ActionListener{
	private JMenuBar menubar;
	private JMenu menu1, menu2,menu3,menu4,menu5;
	// 定义文件菜单
	private JMenuItem demandMenuItem1 = new JMenuItem();
	private JMenuItem demandMenuItem2 = new JMenuItem();
	private JMenuItem demandMenuItem3 = new JMenuItem();

	private JMenuItem addMenuItem = new JMenuItem();
	private JMenuItem alterMenuItem = new JMenuItem();
	private JMenuItem alterPasswordMenuItem = new JMenuItem();
	private JMenuItem checkMenuItem = new JMenuItem();
	private String stuId;

	public MainView(String id){
		this.stuId = id;
		setTitle("学生信息管理系统");
		setSize(600, 400);
		setLocation(400, 100);
		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		// 创建菜单条和菜单
		menubar = new JMenuBar();
		menu1 = new JMenu("个人信息");
		menu2 = new JMenu("课表信息");
		menu3 = new JMenu("个人成绩");
		menu4 = new JMenu("信息维护");
		menu5 = new JMenu("常用信息");
		menubar.add(menu1);
		menubar.add(menu2);
		menubar.add(menu3);
		menubar.add(menu4);
		menubar.add(menu5);
		add(menubar,BorderLayout.NORTH);

		// 创建"个人信息"菜单项
		demandMenuItem1.setText("信息查询");
		addMenuItem.setText("信息添加");
		alterMenuItem.setText("信息修改");
		alterPasswordMenuItem.setText("密码修改");
		demandMenuItem1.addActionListener(this);
		alterMenuItem.addActionListener(this);

		//将菜单项添加到菜单
		menu1.add(demandMenuItem1);
		menu1.add(addMenuItem);
		menu1.add(alterMenuItem);
		//创建“课表信息”菜单项
		demandMenuItem2.setText("课表查询");
		menu2.add(demandMenuItem2);
		//创建“个人成绩”菜单项
		demandMenuItem3.setText("成绩查询");
		menu3.add(demandMenuItem3);
		//创建“信息维护”菜单项
		alterPasswordMenuItem.setText("密码修改");
		menu4.add(alterPasswordMenuItem);
		//创建“常用信息”菜单项
		checkMenuItem.setText("查看");
		menu5.add(checkMenuItem);


	}

	@Override
	public void actionPerformed(ActionEvent e) {
		HashMap<String, String> infoMap = new HashMap<>();
		infoMap = new QueryUserInfo().getInfo(stuId);
		if (e.getSource() == demandMenuItem1) {
			new QueryInfo(infoMap, 0);
		} else if (e.getSource() == alterMenuItem) {
			new QueryInfo(infoMap, 1);
		}
	}
}

